﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Disk DDD = new Disk();
        
        public Form1()
        {
            InitializeComponent();
            Disk1 ADT = new Disk1();
            Disk AL = ADT.Create();
            DDD = AL;
        }
        
        private void form1_load(object sender, EventArgs e)
        {
            
            for (int i = 0; i < DDD.disk.Count; i++)
            {
                String k = DDD.disk[i].GetType().ToString();
                switch (k)
                {
                    case "WindowsFormsApplication1.Audio":
                        listBox3.Items.Add(((Audipopo)DDD.disk[i]).GetBand() + " - " + ((Audio)DDD.disk[i]).GetName());
                        break;
                    case "WindowsFormsApplication1.Clip":
                        listBox3.Items.Add(((Clip)DDD.disk[i]).GetBand() + " - " + ((Clip)DDD.disk[i]).GetName());
                        break;
                    case "WindowsFormsApplication1.Live":
                        listBox3.Items.Add(((Live)DDD.disk[i]).GetBand() + " - " + ((Live)DDD.disk[i]).GetName());
                        break;
                }

            }
        }
        int min = 10000; int max = 0;
        double dur = 0; int index1 = 0, index2 = 0, index3 = 0, index = 0;
        int a = 0, b = 0, c = 0, h = 0;
        private void button2_click(object sender, EventArgs e)
        {
            int olol = listBox3.SelectedIndex;
            String k = DDD.disk[olol].GetType().ToString();
            
            switch (k)
            {
                case "WindowsFormsApplication1.Audio":
                    if (a == 0)
                    {
                        listBox2.Items.Add(((Audio)DDD.disk[olol]).GetBand());
                        listBox1.Items.Add(((Audio)DDD.disk[olol]).GetName());
                        dur += ((Audio)DDD.disk[olol]).GetDur();
                        if (h != 0) listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index1 = index; index++;
                        a = 1; h = 1;
                    }
                    break;
                case "WindowsFormsApplication1.Clip":
                    if (b == 0)
                    {
                        listBox2.Items.Add(((Clip)DDD.disk[olol]).GetBand());
                        listBox1.Items.Add(((Clip)DDD.disk[olol]).GetName());
                        dur += ((Clip)DDD.disk[olol]).GetDur();
                        if (h != 0) listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index2 = index; index++;
                        b = 1; h = 1;
                    }
                    break;
                case "WindowsFormsApplication1.Live":
                    if (c == 0)
                    {
                        listBox2.Items.Add(((Live)DDD.disk[olol]).GetBand());
                        listBox1.Items.Add(((Live)DDD.disk[olol]).GetName());
                        dur += ((Live)DDD.disk[olol]).GetDur();
                        if (h != 0) listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index3 = index; index++;
                        c = 1; h = 1;
                    }
                    break;
            }
        }

        private void button3_click(object sender, EventArgs e)
        {
            int olol = listBox3.SelectedIndex;

            String k = DDD.disk[olol].GetType().ToString();
            switch (k)
            {
                
                case "WindowsFormsApplication1.Audio":
                    if (a == 1)
                    {
                        listBox2.Items.RemoveAt(index1);
                        listBox1.Items.RemoveAt(index1);
                        dur -= ((Audio)DDD.disk[olol]).GetDur();
                        listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index--;
                        if (index1 < index2) index2--;
                        if (index1 < index3) index3--;
                        a = 0;
                    }
                    break;
                case "WindowsFormsApplication1.Clip":
                    if (b == 1)
                    {
                        listBox2.Items.RemoveAt(index2);
                        listBox1.Items.RemoveAt(index2);
                        dur -= ((Clip)DDD.disk[olol]).GetDur();
                        listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index--;
                        if (index2 < index1) index1--;
                        if (index2 < index3) index3--;
                        b = 0;
                    }
                    break;
                case "WindowsFormsApplication1.Live":
                    if (c == 1)
                    {
                        listBox2.Items.RemoveAt(index3);
                        listBox1.Items.RemoveAt(index3);
                        dur -= ((Live)DDD.disk[olol]).GetDur();
                        listBox4.Items.RemoveAt(0);
                        listBox4.Items.Add(dur); index--;
                        if (index3 < index2) index2--;
                        if (index3 < index1) index1--;
                        c = 0;
                    }
                    break;
            }
        }
    }
}
